//--------------------------------------------------------------------------
//Copyright(c) 2011, Sun WenZhong<wanmyqawdr@gmail.com>
//--------------------------------------------------------------------------
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

//--------------------------------------------------------------------------
// Registers file definations for JZ4760
//--------------------------------------------------------------------------
#ifndef _JZ4760_REGS_H_
#define _JZ4760_REGS_H_

#ifdef __cplusplus
extern "C" {
#endif 

//ddr controller's registers file must be located at 32'h1302_0000
struct ddr_ctrl_regs {
    volatile unsigned int                   dstatus;
    volatile unsigned int                   dcfg;
    volatile unsigned int                   dctrl;
    volatile unsigned int                   dlmr;
    volatile unsigned int                   dtiming1;
    volatile unsigned int                   dtiming2;
    volatile unsigned int                   drefcnt;
    volatile unsigned int                   ddqs;
    volatile unsigned int                   ddqsadj;
    volatile unsigned int                   dmmap0;
    volatile unsigned int                   dmmap1;
    volatile unsigned int                   ddelayctrl; 
} __attribute__ ((packed));

//sdram controller's registers file must be located at 32'h1301_0080
struct sdram_ctrl_regs {
    volatile unsigned int                       dmcr;
    volatile unsigned short                     rtcsr;
    volatile const unsigned short pad_rtcsr;
    volatile unsigned short                     rtcnt;
    volatile const unsigned short pad_rtcnt;
    volatile unsigned short                     rtcor;
    volatile const unsigned short pad_rtcor;
    volatile unsigned int                       dmar1;
    volatile unsigned int                       dmar2;
    volatile const unsigned int pad_dmar2[(0x8000 - 0x0094 - 0x4) / 4];
    volatile unsigned int                       sdmr;
} __attribute__ ((packed));

//static memory controller's register file must be located at 32'h1341_0014
struct sm_ctrl_regs {
    volatile unsigned int                     smcr1;
    volatile unsigned int                     smcr2;
    volatile unsigned int                     smcr3;
    volatile unsigned int                     smcr4;
    volatile unsigned int                     smcr5;
    volatile unsigned int                     smcr6;
    volatile const unsigned int pad_smcr6[2];
    volatile unsigned int                     sacr1;
    volatile unsigned int                     sacr2;
    volatile unsigned int                     sacr3;
    volatile unsigned int                     sacr4;
    volatile unsigned int                     sacr5;
    volatile unsigned int                     sacr6;
} __attribute__((packed));

//nand controller's registers file must be located at 32'h1341_0050
struct nand_ctrl_regs {
    volatile unsigned int                     nfcsr;
    volatile unsigned int pad_nfcsr[(0x100 - 0x50 - 0x4) / 4];
    volatile unsigned int                     pncr;
    volatile unsigned int                     pndr;
    volatile const unsigned int               bitcnt;
} __attribute__ ((packed));

//clock controller's registers file must be located at 32'h1000_0000
struct clk_ctrl_regs {
    volatile unsigned int                   cpccr;
    volatile unsigned int                   cppcr;
    volatile unsigned int                   cppsr;
    volatile const unsigned int pad_cppsr[6];
    volatile unsigned int                   cppcr1;
    volatile unsigned int                   cpspr;
    volatile unsigned int                   cpsppr;
    volatile unsigned int                   usbpcr;
    volatile unsigned int                   usbrdt;
    volatile unsigned int                   usbvbfil;
    volatile const unsigned int pad_usbvbfil[2];
    volatile unsigned int                   usbcdr;
    volatile const unsigned int pad_usbcdr[3];
    volatile unsigned int                   i2scdr;
    volatile unsigned int                   lpcdr;
    volatile unsigned int                   msccdr;
    volatile unsigned int                   uhccdr;
    volatile const unsigned int pad_uhccdr;
    volatile unsigned int                   ssicdr;
    volatile unsigned int pad_ssicdr;
    volatile unsigned int                   cimcdr;
    volatile unsigned int                   gpscdr;
    volatile unsigned int                   pcmcdr;
    volatile unsigned int                   gpucdr;
} __attribute__ ((packed));

//interrupt controller's registers file must be located at 32'h1000_1000
struct int_ctrl_regs {
    volatile const unsigned int             icsr0;
    volatile unsigned int                   icmr0;
    volatile unsigned int                   icmsr0;
    volatile unsigned int                   icmcr0;
    volatile const unsigned int             icpr0;
    volatile const unsigned int pad_icpr0[3];
    volatile const unsigned int             icsr1;
    volatile unsigned int                   icmr1;
    volatile unsigned int                   icmsr1;
    volatile unsigned int                   icmcr1;
    volatile const unsigned int             icpr1; 
} __attribute__ ((packed));

//watchdog controller's registers file must be located at 32'h1000_2000
struct wdog_ctrl_regs {
    volatile unsigned short                 tdr;
    volatile const unsigned short pad_tdr;
    volatile unsigned char                  tcer;
    volatile const unsigned char pad_tcer[3];
    volatile unsigned short                 tcnt;
    volatile const unsigned short pad_tcnt;
    volatile unsigned short                 tcsr;
    volatile unsigned short pad_tcsr; 
} __attribute__ ((packed));

//GPIO:  registers file must be located at:
//  A,          32'h1001_0000
//  B,          32'h1001_0100
//  C,          32'h1001_0200
//  D,          32'h1001_0300
//  E,          32'h1001_0400
//  F,          32'h1001_0500
struct gpio_ctrl_regs {
	volatile const unsigned int             pin;
	volatile const unsigned int             dat;
	volatile unsigned int                   dats_flgc;
	volatile unsigned int                   datc;
	volatile const unsigned int             im;
	volatile unsigned int                   ims;
	volatile unsigned int                   imc;
	volatile const unsigned int             pe;
	volatile unsigned int                   pes;
	volatile unsigned int                   pec;
	volatile const unsigned int             fun;
	volatile unsigned int                   funs;
	volatile unsigned int                   func;
	volatile const unsigned int             sel;
	volatile unsigned int                   sels;
	volatile unsigned int                   selc;
	volatile const unsigned int             dir;
	volatile unsigned int                   dirs;
	volatile unsigned int                   dirc;
	volatile const unsigned int             trg;
	volatile unsigned int                   trgs;
	volatile unsigned int                   trgc;
	volatile const unsigned int             flg;
} __attribute__ ((packed));

//otg controller's registers file must be located at 32'h1344_0000
struct otg_ctrl_regs {
    volatile unsigned char              faddr;
    volatile unsigned char              power;
    volatile const unsigned short       intrtx;
    volatile const unsigned short       intrrx;
    volatile unsigned short             intrtxe;
    volatile unsigned short             intrrxe;
    volatile const unsigned char        intrusb;
    volatile unsigned char              intrusbe;
    volatile const unsigned short       frame;
    volatile unsigned char              index;
    volatile unsigned char              testmode;
    volatile unsigned short             txmaxp;
    volatile unsigned short             csr0lh_txcsrlh;
    volatile unsigned short             rxmaxp;
} __attribute__ ((packed));

// UARTs:              registers file must be located at:
// uart0                    32'h1003_0000
// uart1                    32'h1003_1000
// uart2                    32'h1003_2000

struct uart_ctrl_regs {
    volatile unsigned char                          urbr_uthr_udllr;
    volatile const unsigned char pad_urbr_uthr_udllr[3];
    volatile unsigned char                          udlhr_uier;
    volatile const unsigned char pad_udlhr_uier[3];
    volatile unsigned char                          uiir_ufcr;
    volatile const unsigned char pad_uiir_ufcr[3];
    volatile unsigned char                          ulcr;
    volatile const unsigned char pad_ulcr[3];
    volatile unsigned char                          umcr;
    volatile const unsigned char pad_umcr[3];
    volatile const unsigned char                    ulsr;
    volatile const unsigned char pad_ulsr[3];
    volatile const unsigned char                    umsr;
    volatile const unsigned char pad_umsr[3];
    volatile unsigned char                          uspr;
    volatile const unsigned char pad_uspr[3];
    volatile unsigned char                          isr;
    volatile const unsigned char pad_isr[3];
    volatile unsigned char                          umr;
    volatile const unsigned char pad_umr[3];
    volatile unsigned short                         uacr;
    volatile const unsigned short pad_uacr;
} __attribute__ ((packed));

// I2C:             registers file must be located at:
// i2c0                     32'h1005_0000
// i2c1                     32'h1005_1000
struct i2c_ctrl_regs {
    volatile unsigned int                       i2ccon;
    volatile unsigned int                       i2ctar;
    volatile unsigned int                       i2csar;
    volatile const unsigned int pad_i2csar;
    volatile unsigned int                       i2cdc;
    volatile unsigned int                       i2cshcnt;
    volatile unsigned int                       i2cslcnt;
    volatile unsigned int                       i2cfhcnt;
    volatile unsigned int                       i2cflcnt;
    volatile const unsigned int pad_i2cflcnt[2];
    volatile const unsigned int                 i2cintst;
    volatile unsigned int                       i2cintm;
    volatile const unsigned int pad_i2cintm;
    volatile unsigned int                       i2crxtl;
    volatile unsigned int                       i2ctxtl;
    volatile const unsigned int                 i2ccint;
    volatile const unsigned int                 i2ccrxuf;
    volatile const unsigned int                 i2ccrxof;
    volatile const unsigned int                 i2cctxof;
    volatile const unsigned int                 i2ccrxreq;
    volatile const unsigned int                 i2cctxabt;
    volatile const unsigned int                 i2ccrxdn;
    volatile const unsigned int                 i2ccact;
    volatile const unsigned int                 i2ccstp;
    volatile const unsigned int                 i2ccstt;
    volatile const unsigned int                 i2ccgc;
    volatile unsigned int                       i2cenb;
    volatile const unsigned int                 i2cst;
    volatile const unsigned int pad_i2cst[3];
    volatile const unsigned int                 i2cabtsrc;
    volatile const unsigned int pad_i2cabtsrc[4];
    volatile unsigned int                       i2csdasu;
    volatile unsigned int                       i2cackgc;
    volatile const unsigned int                 i2cenbst;
} __attribute__ ((packed));

// MMC:             registers file must be located at:
// mmc0                         32'h1002_1000
// mmc1                         32'h1002_2000
struct mmc_ctrl_regs {
    volatile unsigned short                     msc_ctrl;
    volatile const unsigned short pad_msc_ctrl;
    volatile const unsigned int                 msc_stat;
    volatile unsigned short                     msc_clkrt;
    volatile const unsigned short pad_msc_clkrt;
    volatile unsigned int                       msc_cmdat;
    volatile unsigned short                     msc_resto;
    volatile const unsigned short pad_msc_resto;
    volatile unsigned int                       msc_rdto;
    volatile unsigned short                     msc_blklen;
    volatile const unsigned short pad_msc_blklen;
    volatile unsigned short                     msc_nob;
    volatile const unsigned short pad_msc_nob;
    volatile const unsigned short               msc_snob;
    volatile const unsigned short pad_msc_snob;
    volatile unsigned int                       msc_imask;
    volatile unsigned short                     msc_ireg;
    volatile const unsigned short pas_msc_ireg;
    volatile unsigned char                      msc_cmd;
    volatile const unsigned char pad_msc_cmd[3];
    volatile unsigned int                       msc_arg;
    volatile const unsigned short               msc_res;
    volatile const unsigned int                 msc_rxfifo;
    volatile unsigned int                       msc_txfifo;
    volatile unsigned int                       msc_lpm;
} __attribute__ ((packed));

#ifdef __cplusplus
}
#endif 

#endif 
